package dao;

import java.util.List;

import org.hibernate.classic.Session;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
public class ProductDAO  {
	public static final String TYPEID = "typeid";
	public static final String PRODUCTNAME = "productname";
	public static final String PRICE = "price";
	public static final String REMARK = "remark";
	private SessionFactory sessionFactory;
	private int type;
    public List getAllProduct(){
    	Session session=sessionFactory.openSession();
    	Query query=session.createQuery("from Product c");
    	List products=query.list();
    	session.close();
    	 int i=products.size();
		 System.out.println("the number is "+i);
    	return products;
    }
    public List selectProduct(int type){
    	Session session=sessionFactory.openSession();
    	Query query=session.createQuery("from Product u where u.typeid=?");
    	query.setParameter(0,type);
    	List products=query.list();
    	session.close();
    	return products;
    }
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
    public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}